home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-25 | 26.2 KB | 804 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: DrawLink.cpp
- // Release Version: $ ODF 1 $
- //
- // Author: Henri Lamiraux
- // Linking added by: M.Boetcher
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "ODFDraw.hpp"
-
- #ifndef DRAWLINK_H
- #include "DrawLink.h"
- #endif
-
- #ifndef DRAWCONT_H
- #include "DrawCont.h"
- #endif
-
- #ifndef DEFINES_K
- #include "Defines.k"
- #endif
-
- #ifndef DRAWPART_H
- #include "DrawPart.h"
- #endif
-
- #ifndef DRAWSEL_H
- #include "DrawSel.h"
- #endif
-
- #ifndef BASESHP_H
- #include "BaseShp.h"
- #endif
-
- #ifndef BOUNDSHP_H
- #include "BoundShp.h"
- #endif
-
- #ifndef LINESHP_H
- #include "LineShp.h"
- #endif
-
- #ifndef OVALSHP_H
- #include "OvalShp.h"
- #endif
-
- #ifndef RECTSHP_H
- #include "RectShp.h"
- #endif
-
- #ifndef RRECTSHP_H
- #include "RRectShp.h"
- #endif
-
- #ifndef TEXTSHP_H
- #include "TextShp.h"
- #endif
-
- #ifndef GROUPSHP_H
- #include "GroupShp.h"
- #endif
-
- #ifndef DRAWPRXY_H
- #include "DrawPrxy.h"
- #endif
-
- // ----- Framework Includes -----
-
- #ifndef FWLNKITE_H
- #include "FWLnkIte.h"
- #endif
-
- #ifndef FWPXYITE_H
- #include "FWPxyIte.h"
- #endif
-
- #ifndef FWFRAME_H
- #include "FWFrame.h"
- #endif
-
- #ifndef FWINTER_H
- #include "FWInter.h"
- #endif
-
- #ifndef FWITERS_H
- #include "FWIters.h"
- #endif
-
- #ifndef FWPRTITE_H
- #include "FWPrtIte.h"
- #endif
-
- #ifndef FWPRESEN_H
- #include "FWPresen.h"
- #endif
-
- #ifndef FWPXYFRM_H
- #include "FWPxyFrm.h"
- #endif
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef FWCLNINF_H
- #include "FWClnInf.h"
- #endif
-
- #ifndef FWBARRAY_H
- #include "FWBArray.h"
- #endif
-
- // ----- Foundation Includes -----
-
- #ifndef FWORDCOL_H
- #include "FWOrdCol.h"
- #endif
-
- #ifndef FWMEMMGR_H
- #include "FWMemMgr.h"
- #endif
-
- // for FW_SOMEnvironment
- #ifndef FWSOMENV_H
- #include "FWSOMEnv.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_Module_OpenDoc_StdProps_defined
- #include <StdProps.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdTypes_defined
- #include <StdTypes.xh>
- #endif
-
- #ifndef SOM_ODStorageUnit_xh
- #include <StorageU.xh>
- #endif
-
- #ifndef SOM_ODUndo_xh
- #include <Undo.xh>
- #endif
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #ifndef SOM_ODLink_xh
- #include <Link.xh>
- #endif
-
- #ifndef SOM_ODLinkSpec_xh
- #include <LinkSpec.xh>
- #endif
-
- #ifndef SOM_ODLinkSource_xh
- #include <LinkSrc.xh>
- #endif
-
- //========================================================================================
- // Runtime Information
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment odfdraw
- #endif
-
- FW_DEFINE_AUTO(CDrawPublishLinkCollection)
- FW_DEFINE_AUTO(CDrawPublishLinkCollectionIterator)
- FW_DEFINE_AUTO(CDrawSubscribeLinkCollection)
- FW_DEFINE_AUTO(CDrawSubscribeLinkCollectionIterator)
- FW_DEFINE_AUTO(CDrawLinkManager)
-
- //========================================================================================
- // class CDrawPublishLink
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CDrawPublishLink::CDrawPublishLink
- //----------------------------------------------------------------------------------------
-
- CDrawPublishLink::CDrawPublishLink(Environment* ev, ODUpdateID updateID,
- FW_CPresentation* presentation,
- CDrawSelection* drawSelection,
- FW_Boolean saveSelection) :
- FW_CLinkSource(ev, updateID, presentation),
- fDrawSelection(drawSelection),
- fPublishedContent(NULL)
- {
- CDrawContent* content = NULL;
- if (saveSelection) // Save the selected shapes so they can be published
- content = fDrawSelection->GetDrawContent(ev);
-
- fPublishedContent = FW_NEW(CDrawLinkSourceContent, (ev,
- (CDrawPart*) presentation->GetPart(ev),
- content));
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPublishLink::~CDrawPublishLink
- //----------------------------------------------------------------------------------------
-
- CDrawPublishLink::~CDrawPublishLink()
- {
- delete fPublishedContent;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPublishLink::LinkEstablished - Override
- //----------------------------------------------------------------------------------------
-
- void CDrawPublishLink::LinkEstablished(Environment* ev)
- {
- //---- Mark the collected shapes as published
- CDrawContentShapeIterator ite(fPublishedContent);
- for (CBaseShape* shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
- {
- shape->SetPublishLink(ev, this);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPublishLink::ExternalizeLinkContent - Override
- //----------------------------------------------------------------------------------------
-
- void CDrawPublishLink::ExternalizeLinkContent(Environment* ev, ODStorageUnit* linkSU)
- {
- // Remove extra properties (ODLinkSource::Clear removed only the content property)
- FW_SURemoveProperty(ev, linkSU, kODPropContentFrame);
- FW_SURemoveProperty(ev, linkSU, kODPropCloneKindUsed);
-
- // -- Pick a frame, any frame --
- FW_CPresentationFrameIterator piter(ev, fPresentation);
- FW_CFrame* frame = piter.First(ev);
- FW_ASSERT(frame);
-
- fDataInterchange->ExternalizeData(ev, fPublishedContent, frame, linkSU, FW_kLinkStorage, kODCloneToLink);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPublishLink::HasEmbeddedFrame
- //----------------------------------------------------------------------------------------
- FW_Boolean CDrawPublishLink::HasEmbeddedFrame(Environment* ev, ODFrame* odFrame)
- {
- // Is odFrame involved in this link source? (called by DoUpdateLinks)
-
- // --- Find out whether odFrame is involved in any link source ---
- if (odFrame->GetLinkStatus(ev) == kODInLinkSource)
- {
- // -- Find out whether odFrame is one of my frames --
- FW_CFrame* fwFrame = FW_CFrame::ODtoFWFrame(ev, odFrame);
- if (fwFrame)
- {
- CDrawContentShapeIterator iter(fPublishedContent);
- for (CBaseShape* shape = iter.First(); iter.IsNotComplete(); shape = iter.Next())
- {
- if ((shape->GetShapeType() == kProxyShape) && (((CProxyShape*)shape)->IsEmbeddedFrame(ev, odFrame)))
- return TRUE;
- }
- }
- }
-
- return FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPublishLink::GetFrameToRevealLink
- //----------------------------------------------------------------------------------------
- FW_CFrame* CDrawPublishLink::GetFrameToRevealLink(Environment* ev)
- {
- // Just return the presentation's first display frame
- FW_CPresentationFrameIterator piter(ev, fPresentation);
- return piter.First(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPublishLink::DoSelect
- //----------------------------------------------------------------------------------------
- void CDrawPublishLink::DoSelect(Environment* ev, FW_CFrame* /*frame*/)
- {
- // Select the published shapes
- fDrawSelection->SelectContent(ev, fPublishedContent);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPublishLink::AddShape
- //----------------------------------------------------------------------------------------
- void CDrawPublishLink::AddShape(Environment* ev, CBaseShape* shape)
- {
- shape->SetPublishLink(ev, this);
- fPublishedContent->AddShape(ev, shape);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPublishLink::RemoveShape
- //----------------------------------------------------------------------------------------
- void CDrawPublishLink::RemoveShape(Environment* ev, CBaseShape* shape)
- {
- fPublishedContent->RemoveShape(ev, shape);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPublishLink::DoExternalizeLink
- //----------------------------------------------------------------------------------------
-
- void CDrawPublishLink::DoExternalizeLink(Environment* ev, ODStorageUnit* storageUnit,
- FW_CCloneInfo* cloneInfo)
- {
- //--- Write the number of shapes in the link ---
- unsigned long shapeCount = fPublishedContent->CountShapes();
- FW_ASSERT(shapeCount != 0);
- FW_CByteArray byteArray(&shapeCount, sizeof(unsigned long));
- storageUnit->SetValue(ev, byteArray);
-
- //--- Write the externalization index for each shape in the link ---
- CDrawContentShapeIterator iter(fPublishedContent);
- for (CBaseShape* shape = iter.First(); iter.IsNotComplete(); shape = iter.Next())
- {
- short extIndex = shape->GetExternalizationIndex();
- byteArray.Set(&extIndex, sizeof(short));
- storageUnit->SetValue(ev, byteArray);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPublishLink::IsEmpty
- //----------------------------------------------------------------------------------------
- FW_Boolean CDrawPublishLink::IsEmpty()
- {
- return (fPublishedContent->CountShapes() == 0);
- }
-
- //========================================================================================
- // class CDrawSubscribeLink
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CDrawSubscribeLink::CDrawSubscribeLink
- //----------------------------------------------------------------------------------------
-
- CDrawSubscribeLink::CDrawSubscribeLink(Environment* ev, ODLink* odLink,
- FW_CPresentation* presentation,
- CDrawSelection* drawSelection,
- ODLinkInfo* linkInfo,
- FW_Boolean createGroupShape) :
- FW_CLinkDestination(ev, odLink, linkInfo, presentation),
- fDrawPart((CDrawPart*) presentation->GetPart(ev)),
- fDrawSelection(drawSelection),
- fLinkedContent(NULL),
- fGroupShape(NULL),
- fFirstUpdate(true),
- fFirstOffset(true)
- {
- fUpdateOffset.Clear();
-
- //---- Create a new content object to hold the shapes in this link ----
- fLinkedContent = FW_NEW(CDrawLinkContent, (ev, (CDrawPart*) presentation->GetPart(ev), this));
-
- if (createGroupShape)
- {
- //---- Create a new group shape to represent the linked shapes ----
- fGroupShape = FW_NEW(CGroupShape, ());
- fGroupShape->SetSubscribeLink(ev, this);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSubscribeLink::~CDrawSubscribeLink
- //----------------------------------------------------------------------------------------
-
- CDrawSubscribeLink::~CDrawSubscribeLink()
- {
- FW_SOMEnvironment ev;
- this->DeleteShapes(ev);
- delete fLinkedContent;
- fDrawPart->RemoveShapeFromPart(ev, fGroupShape);
- delete fGroupShape;
- }
-
- //---------------------------------------------------------------------------------------
- // CDrawSubscribeLink::DoUpdateLink - Override
- //---------------------------------------------------------------------------------------
-
- FW_Boolean CDrawSubscribeLink::DoUpdateLink(Environment* ev, ODStorageUnit* linkContentSU, ODPasteAsResult* embedAsInfo)
- {
- // Find a frame to use for the scope frame
- FW_CPresentationFrameIterator piter(ev, fPresentation);
- FW_CFrame* frame = piter.First(ev);
- FW_ASSERT(frame);
-
- if (!fFirstUpdate)
- fLinkedContent->EmptyShapes(ev); // remove linked shapes from our content
-
- // Read new shapes from the link SU into our content
- FW_Boolean result = (fDataInterchange->InternalizeData(ev, fLinkedContent, frame, linkContentSU,
- FW_kLinkStorage, kODCloneFromLink, embedAsInfo)
- != FW_kInternalizeFailed);
- if (result)
- {
- // Merge newly-read link data with part data
- this->UpdateLinkedContent(ev);
-
- // Force all frames to be redrawn
- fPresentation->Invalidate(ev);
- }
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSubscribeLink::UpdateLinkedContent
- //----------------------------------------------------------------------------------------
-
- void CDrawSubscribeLink::UpdateLinkedContent(Environment* ev)
- {
- // If we got this far, the link data was read successfully.
-
- if (fFirstUpdate) // Add the group shape to the part
- {
- fDrawPart->AddShapeToPart(ev, fGroupShape);
- }
- else // Delete obsolete data
- {
- fGroupShape->EmptyShapes(true); // remove shapes and delete them
- }
-
- // Roll the new shapes into the group shape
- fLinkedContent->GroupShapes(ev, fGroupShape);
-
- if (!fFirstOffset && fUpdateOffset != FW_kZeroPoint) // updating an existing link
- {
- // move the linked shapes to their proper position
- fGroupShape->OffsetShape(ev, fUpdateOffset.x, fUpdateOffset.y);
- }
-
- // Redraw the new shapes
- fLinkedContent->RedrawShapes(ev);
-
- fFirstUpdate = false;
- fFirstOffset = false;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSubscribeLink::BreakLink - Override
- //----------------------------------------------------------------------------------------
- void CDrawSubscribeLink::BreakLink(Environment* ev)
- {
- FW_CLinkDestination::BreakLink(ev);
-
- // Remove linked shapes; if link is re-established new ones will be created
- fLinkedContent->EmptyShapes(ev); // remove shapes from content
- fGroupShape->EmptyShapes(true); // remove shapes and delete them
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSubscribeLink::RestoreLink - Override
- //----------------------------------------------------------------------------------------
- void CDrawSubscribeLink::RestoreLink(Environment* ev, FW_CPart* part)
- {
- // Reset flag used in DoUpdateLink
- fFirstUpdate = true;
-
- FW_CLinkDestination::RestoreLink(ev, part);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSubscribeLink::SetGroupShape
- //----------------------------------------------------------------------------------------
- void CDrawSubscribeLink::SetGroupShape(Environment* ev, CGroupShape* groupShape)
- {
- fGroupShape = groupShape;
- groupShape->SetSubscribeLink(ev, this);
-
- // Add the grouped shapes to the linked content
- CShapeCollectionIterator it(groupShape->GetShapeList());
- for (CBaseShape* shape = it.First(); it.IsNotComplete(); shape = it.Next())
- {
- fLinkedContent->AddShape(ev, shape);
- }
-
- if (fLinkedContent->CountShapes() != 0)
- fFirstUpdate = false; // so that DoUpdateLink empties it before reading new shapes
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSubscribeLink::AddShape
- //----------------------------------------------------------------------------------------
- void CDrawSubscribeLink::AddShape(Environment* ev, CBaseShape* shape)
- {
- // Called by Link Manager when internalizing destination links
- fLinkedContent->AddShape(ev, shape);
- fGroupShape->AddShape(shape);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSubscribeLink::DeleteShapes
- //----------------------------------------------------------------------------------------
- void CDrawSubscribeLink::DeleteShapes(Environment* ev)
- {
- // Called when undoing a Paste As (breaking a dest link)
- fDrawSelection->CloseSelection(ev);
- fLinkedContent->EmptyShapes(ev); // remove shapes from content
- fGroupShape->EmptyShapes(true); // remove shapes and delete them
-
- // Remove the group shape from the part (destructor will delete it)
- fDrawPart->RemoveShapeFromPart(ev, fGroupShape);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSubscribeLink::SelectShapes
- //----------------------------------------------------------------------------------------
- void CDrawSubscribeLink::SelectShapes(Environment* ev)
- {
- fDrawSelection->CloseSelection(ev);
- fDrawSelection->AddToSelection(ev, fGroupShape, TRUE);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSubscribeLink::DoExternalizeLink
- //----------------------------------------------------------------------------------------
-
- void CDrawSubscribeLink::DoExternalizeLink(Environment* ev, ODStorageUnit* storageUnit,
- FW_CCloneInfo* cloneInfo)
- {
- //--- There is a single group shape in the link ---
- FW_ASSERT(fGroupShape);
- unsigned long shapeCount = 1;
- FW_CByteArray byteArray(&shapeCount, sizeof(unsigned long));
- storageUnit->SetValue(ev, byteArray);
-
- //--- Write the export index for the group shape ---
- short extIndex = fGroupShape->GetExternalizationIndex();
- byteArray.Set(&extIndex, sizeof(short));
- storageUnit->SetValue(ev, byteArray);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSubscribeLink::AdjustUpdateOffset
- //----------------------------------------------------------------------------------------
- void CDrawSubscribeLink::AdjustUpdateOffset(Environment* ev, const FW_CPoint& delta)
- {
- fUpdateOffset += delta;
- }
-
- //========================================================================================
- // class CDrawLinkManager
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CDrawLinkManager constructor
- //----------------------------------------------------------------------------------------
-
- CDrawLinkManager::CDrawLinkManager(Environment* ev, CDrawPart* part):
- FW_CLinkManager(ev, part),
- fDrawPart(part)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawLinkManager destructor
- //----------------------------------------------------------------------------------------
-
- CDrawLinkManager::~CDrawLinkManager()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawLinkManager::NewLinkSource - Override
- //----------------------------------------------------------------------------------------
-
- FW_CLinkSource* CDrawLinkManager::NewLinkSource(Environment* ev, ODUpdateID changeID,
- FW_CPresentation* presentation)
- {
- return new CDrawPublishLink(ev, changeID,
- presentation, fDrawPart->fDrawSelection,
- TRUE); // saveSelection = TRUE
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawLinkManager::NewLinkDestination - Override
- //----------------------------------------------------------------------------------------
-
- FW_CLinkDestination* CDrawLinkManager::NewLinkDestination(Environment* ev, ODLink *odLink,
- ODLinkInfo* linkInfo,
- FW_CPresentation* presentation)
- {
- return new CDrawSubscribeLink(ev, odLink, presentation, fDrawPart->fDrawSelection, linkInfo);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawLinkManager::DoChangeLinkStatus - Override
- //----------------------------------------------------------------------------------------
-
- void CDrawLinkManager::DoChangeLinkStatus(Environment* ev, ODFrame* odFrame)
- {
- // call ODFrame::ChangeLinkStatus on any embedded frames that are involved in a link
- // when a link is created, broken, moved, etc.
- // odFrame is the frame of this part whose link status has changed.
-
- FW_CEmbeddingFrame* frame = FW_CEmbeddingFrame::ODtoFWEmbeddingFrame(ev, odFrame);
- if (frame)
- {
- ODLinkStatus linkStatus = odFrame->GetLinkStatus(ev);
-
- // Only need to propagate linkStatus to embedded frames that don't participate in
- // any of this part's links; otherwise their local link status takes precedence.
-
- CDrawContentShapeIterator iter(fDrawPart->GetDrawContent());
- for (CBaseShape* shape = iter.First(); iter.IsNotComplete(); shape = iter.Next())
- {
- if (shape->GetShapeType() == kProxyShape)
- {
- CProxyShape* proxyShape = (CProxyShape*)shape;
- if (!proxyShape->IsPublished() && !proxyShape->IsSubscribed())
- {
- FW_CProxyEmbeddedFrameIterator efiter(ev, proxyShape);
- for (ODFrame* embFrame = efiter.First(ev); efiter.IsNotComplete(ev); embFrame = efiter.Next(ev))
- embFrame->ChangeLinkStatus(ev, linkStatus);
- }
- }
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawLinkManager::CreateLink - Override
- //----------------------------------------------------------------------------------------
- ODLinkSource* CDrawLinkManager::CreateLink(Environment* ev, ODByteArray* data)
- {
- // CreateLink is overridden so that we can delete the pending clipboard publish link.
- // This prevents the link spec from being re-used to create more than one link.
-
- FW_Boolean isLinkSpecOnClipboard = (GetPendingDropLink(ev) == NULL);
- ODLinkSource* odLinkSource = FW_CLinkManager::CreateLink(ev, data);
- if (isLinkSpecOnClipboard)
- this->DeletePendingClipboardLink(ev);
- return odLinkSource;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawLinkManager::UndoPasteAs
- //----------------------------------------------------------------------------------------
- void CDrawLinkManager::UndoPasteAs(Environment* ev, CDrawSubscribeLink* link)
- {
- //--- Remove subscribed shapes from the document ---
- link->DeleteShapes(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawLinkManager::RedoPasteAs
- //----------------------------------------------------------------------------------------
- void CDrawLinkManager::RedoPasteAs(Environment* ev, CDrawSubscribeLink* link)
- {
- FW_UNUSED(ev);
- FW_UNUSED(link);
-
- // When the restored link is updated, new subscriber shapes will be created
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawLinkManager::SelectSubscribedShapes
- //----------------------------------------------------------------------------------------
- void CDrawLinkManager::SelectSubscribedShapes(Environment* ev, CDrawSubscribeLink* link)
- {
- fDrawPart->fDrawSelection->SelectContent(ev, (CDrawContent*) link->fLinkedContent); /* PRIVATE */
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawLinkManager::RevealLink - Override
- //----------------------------------------------------------------------------------------
- void CDrawLinkManager::RevealLink(Environment* ev, ODLinkSource* linkSource)
- {
- CDrawPublishLink* sourceLink = (CDrawPublishLink*) ODtoFWLinkSource(ev, linkSource);
- if (sourceLink == NULL) return; // not our link!?
-
- // Choose a display frame for the source content
- FW_CFrame* frame = sourceLink->GetFrameToRevealLink(ev);
- if (frame)
- {
- // Ensure the display frame is revealed
- if (!frame->GetWindow(ev)->IsActive(ev))
- frame->GetWindow(ev)->Select(ev);
-
- // ----- Activate the frame -----
- if (!frame->HasSelectionFocus(ev))
- {
- FW_CFrameFacetIterator iter(ev, frame); // find a facet
- frame->PrivActivateFrame(ev, iter.First(ev));
- }
-
- // Select the shape(s) that make up this link source
- sourceLink->DoSelect(ev, frame);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawLinkManager::GetSUValue
- //----------------------------------------------------------------------------------------
-
- ODULong CDrawLinkManager::GetSUValue(Environment* ev, ODStorageUnit* su,
- unsigned long size, void *buffer)
- {
- // Convenience function; also makes code easier to read
- FW_CByteArray ba;
- ODULong bytesRead = su->GetValue(ev, size, ba);
- ba.CopyBuffer(buffer, bytesRead);
-
- return bytesRead;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawLinkManager::DoInternalizeOneDestLink - Override
- //----------------------------------------------------------------------------------------
-
- FW_CLinkDestination* CDrawLinkManager::DoInternalizeOneDestLink(Environment* ev, ODStorageUnit* storageUnit,
- ODLink* odLink, ODLinkInfo* linkInfo)
- {
- //--- Create a subscriber object for this link ---
- CDrawSubscribeLink* destLink = new CDrawSubscribeLink(ev, odLink,
- fDrawPart->GetMainPresentation(),
- fDrawPart->fDrawSelection, linkInfo,
- false); // don't create group shape
-
- //--- Read the number of shapes in the link ---
- unsigned long shapeCount;
- GetSUValue(ev, storageUnit, sizeof(unsigned long), &shapeCount);
- FW_ASSERT(shapeCount == 1); // There should be a single group shape
-
- //--- Read each shape index and add the shape to the source link ---
- short extIndex;
- GetSUValue(ev, storageUnit, sizeof(short), &extIndex);
- CBaseShape* shape = fDrawPart->FindShapeWithIndex(extIndex);
- FW_ASSERT(shape);
- if (shape && shape->GetShapeType() == kGroupShape)
- {
- destLink->SetGroupShape(ev, (CGroupShape*)shape);
- }
-
- return destLink;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawLinkManager::DoInternalizeOneSourceLink - Override
- //----------------------------------------------------------------------------------------
-
- FW_CLinkSource* CDrawLinkManager::DoInternalizeOneSourceLink(Environment* ev,
- ODStorageUnit* storageUnit,
- ODUpdateID updateID)
- {
- //--- Create a publish object for this source link ---
- CDrawPublishLink* sourceLink = new CDrawPublishLink(ev, updateID, fDrawPart->GetMainPresentation(), fDrawPart->fDrawSelection, FALSE);
-
- //--- Read the number of shapes in the link ---
- unsigned long shapeCount;
- GetSUValue(ev, storageUnit, sizeof(unsigned long), &shapeCount);
-
- //--- Read each shape index and add the shape to the source link ---
- unsigned long shapesInLink = 0;
- short extIndex;
- while (shapeCount > 0)
- {
- GetSUValue(ev, storageUnit, sizeof(short), &extIndex);
- CBaseShape* shape = fDrawPart->FindShapeWithIndex(extIndex);
- if (shape)
- {
- sourceLink->AddShape(ev, shape);
- shapesInLink++;
- }
- shapeCount--;
- }
-
- //--- If no linked shapes were found, discard the link ---
- if (shapesInLink == 0)
- {
- delete sourceLink;
- sourceLink = NULL;
- }
-
- return sourceLink;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawLinkManager::GetSourceLinkFormat - Override
- //----------------------------------------------------------------------------------------
-
- ODValueType CDrawLinkManager::GetSourceLinkFormat(Environment* ev)
- {
- return kPublishFormat;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawLinkManager::GetDestLinkFormat - Override
- //----------------------------------------------------------------------------------------
-
- ODValueType CDrawLinkManager::GetDestLinkFormat(Environment* ev)
- {
- return kSubscribeFormat;
- }
-